import {
  rpxToPx
} from "../../utils";
Component({
  data: {
    pageSize: 15,
    current: 0,
    sortList: [],
    sortEpisodesList:[],
    swiperHeight: 0,
    animationData: null,
    skitTitle: "",
    ablumEpisodes: 0,
    needLoading: true,
  },
  properties: {
    needChangeVideo: {
      type: Boolean,
      value: false,
    },
    episodes: {
      type: Array,
      observer(value) {
        // console.log("currentVideo",value);
        this.initTab(value)
      }
    },
    isFullScreen: {
      type: Boolean,
      value: false,
    },
    currentAblum: {
      type: Object,
    },
    currentVideo: {
      type: Object,
      observer(value) {
        // console.log("currentVideo",value);
        // this.initTab(value)
      }
    }
  },
  ready() {
    const dialogHeight = rpxToPx(1204);
    this.setData({
      dialogHeight,
    });
    setTimeout(() => {
      this.setData({
        needLoading: false,
      })
    }, 1000);

  },
  methods: {
    initTab(arr) {
    
      let pageSize = this.data.pageSize;
      let len = arr.length;
      let index = 0;
      let sortList = [];
      let sortEpisodesList=[];
      while (index < len) {
        let _arr = arr.slice(index, index + pageSize);
        if (_arr.length === 0) {
          break;
        } else {
          let sort=_arr.length === 1 ? `${index+1}` : `${index+1}-${index+_arr.length}`;
          sortList.push(sort);
          sortEpisodesList.push(_arr);
        }
        index+=pageSize;
      }
 
      this.setData({
        sortList:sortList,
        sortEpisodesList:sortEpisodesList
      })
    },
    handleTabbarChange(event) {
      const current = event.detail.current
      this.setData({
        current: current
      });
    },
    switchTap(e) {
      const {
        current
      } = e.detail;

      this.setData({
        current,
      });
    },
    async requestData() {
      console.log("这里需要请求数据");
    },
    onTapEpisodes(e) {
      const {
        episodeitem
      } = e.currentTarget.dataset;
      // console.log(episodeitem)
      // if (episodeitem.episodes_locking) {
      //   tt.showToast({
      //     title: "积分不足",
      //     icon: "none"
      //   });
      //   return;
      // }
      console.log("onTapEpisodes")
      this.triggerEvent("episodesChangeHandler", {
        episodeitem
      })
    },
    maskHandler() {
      // this.setData({
      //   needChangeVideo: false,
      // })
      this.triggerEvent('cancel');
    },
    cancel() {
      this.triggerEvent('cancel');
    },
  }
})